package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import util.DBUtil;
import dao.AreaDao;

public class AreaDaoImpl implements AreaDao {

	@Override
	public List<String> getAreaName(String matchStr) {
		List<String> list = new ArrayList<String>();
		Connection connection = null;
		PreparedStatement pst = null;
		String sql = "select area from area where area like ?";
		try {
			connection = DBUtil.createConnection();
			pst=connection.prepareStatement(sql);
			pst.setString(1, matchStr+"%");
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				String areaName=rs.getString("area");
				list.add(areaName);
			}
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
			return list;
		} finally{
			DBUtil.close(connection, pst, null);
		}
	}

}
